package com.ag.zrt.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.aspectj.lang.annotation.Around;
import org.springframework.stereotype.Service;

import com.ag.bean.TbType;
import com.ag.common.AgException;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.zrt.dao.TbTypeDAO;
import com.ag.zrt.service.TypeService;
@Service("TypeService")
public class TypeServiceImpl implements TypeService {
	@Resource(name="ZRTTbTypeDAO")
	private TbTypeDAO typeDAO;
	@Resource(name="iDServiceImpl")
	private IIDService idService;

	public void setTypeDAO(TbTypeDAO typeDAO) {
		this.typeDAO = typeDAO;
	}

	public void update(TbType type) {
		// TODO Auto-generated method stub
		type.setA(IDUtil.PRESERVE);
		typeDAO.attachDirty(type);

	}

	public void delete(TbType type) {
		// TODO Auto-generated method stub
		TbType tt = typeDAO.findById(type.getTpyeId());
		tt.setA(IDUtil.DELETE);
		typeDAO.attachDirty(tt);

	}

	public List<TbType> findAll() {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		sb.append("from TbType tt where tt.a = "+IDUtil.PRESERVE);
		return typeDAO.find(sb.toString());
	}

	public TbType findById(String Id) {
		// TODO Auto-generated method stub
		return typeDAO.findById(Id);
	}

	public void save(TbType type) throws Exception {
		// TODO Auto-generated method stub
		String typeId = idService.findTablePK(IDUtil.TB_TYPE);
		type.setTpyeId(typeId);
		type.setA(IDUtil.PRESERVE);
		typeDAO.save(type);

	}

}
